package cn.newstrength.shihaipeng.step;

import cn.newstrength.wtdf.plugin.param.TranParams;
import cn.newstrength.wtdf.plugin.result.TranResult;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.exception.PAIException;
import cn.newstrength.wtdf.web.mybatis.service.MapperService;
import cn.newstrength.wtdf.web.mybatis.service.impl.MapperServiceImpl;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;
import cn.newstrength.wtdf.web.util.StepUtils;
import java.util.Map;

public class InsertStep implements OperationStep {
    public InsertStep() {
    }

    public int excute(Operation oper) throws PAIException {
        DataContext dc = oper.getContext();
        String mapSet = dc.getElementValue("mapSet");
        Map<String, Object> input = StepUtils.getInputValue(oper, mapSet);
        String resource = dc.getElementValue("resource");
        MapperService service = (MapperService)oper.getBean("mapperService", MapperServiceImpl.class);
        TranParams<Map<String, Object>> params = new TranParams(input);
        params.setSummary("写入数据");
        params.setTranType("InsertStep");
        params.setResource(resource);
        TranResult<Map<String, Object>> tranResult = service.insert(params);
        oper.setTranResult(tranResult);
        return 0;
    }

    public int init(Map<String, String> param) {
        return 0;
    }
}

